package logic

import (
	"context"
	"everyone/B/rpc_B/everyoneclient"

	"everyone/B/api_B/internal/svc"
	"everyone/B/api_B/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsListLogic) GoodsList(req *types.GoodsListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	list, err := l.svcCtx.Everyone.GoodsList(l.ctx, &everyoneclient.GoodsListRequest{
		Page:        req.Page,
		PageSize:    req.PageSize,
		GoodsStatue: req.PageSize,
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  "展示失败",
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "展示成功",
		Data: map[string]interface{}{"list": list},
	}, nil
}
